<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    
	
	<title>_进出存报表</title>
	<script type="text/javascript">
		var datatable_content;
		var formParam ;
		function onQuery() {
			$("#queryForm").submit();
		}
		function initTable(){
			datatable_content = $("#contentTable").dataTable({
			   "bServerSide":true,
			   "bAutoWidth":false,
	           "sAjaxSource":'${ctx}/invHistory/query',
	           "fnServerData": callback,
	           "fnRowCallback":rowCallBack,
	           "bFilter": false,
	           "aLengthMenu": [ 10 ],
	           "bSort": false,
	           "sZeroRecords": "查询无记录！",
	           "bProcessing": true,
	           "oLanguage": {
	               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
	            },
	             "aoColumns":[
	             	 {"mData": null},
	             	 {"mData": "customer.customerName"},
	             	 {"mData": "warehouse.groupName"},
	             	 {"mData": "invDate"},
	             	 {"mData": "sku"},
	             	 {"mData": "skuName"},
	             	 {"mData": null},
	             	 {"mData": "inNum"},
	             	 {"mData": "outNum"},
	             	 {"mData": "adjustNum"},
	             	 {"mData": null},
	             ] ,
	             "aoColumnDefs":[
					   /*  {"aTargets": [4],
							  "mRender": function (data, display, row) {
								  if(!row.sku){
									  return "";
								  }else{
									  return row.sku;
								  }
								}
						},   
						 {"aTargets": [5],
							  "mRender": function (data, display, row) {
								  if(!row.sku){
									  return "";
								  }else{
									  return row.sku.skuName;
								  }
								}
						}, */ 
						{"aTargets": [6],
							  "mRender": function (data, display, row) {
								  return (parseInt(row.salesNum)+ parseInt(row.orderNum) - parseInt(row.inNum) + parseInt(row.outNum));
								}
						},
						{"aTargets": [10],
							  "mRender": function (data, display, row) {
								  return (parseInt(row.salesNum)+ parseInt(row.orderNum));
								}
						}
	         	  ], 
			});
		}
		function callback(sSource, aoData, fnCallback ) {
		   $.ajax({ 
		       "type": "post",
		       "contentType": "application/json", 
		       "url": sSource,    
		       "dataType": "json",   
		       "data": JSON.stringify(aoData.concat(formParam)),
		       "success": fnCallback  
		   });
		}
		/**
		*创建了行的回调
		*nRow为当前的tr
		*/
		function rowCallBack(nRow, aData, iDisplayIndex, iDisplayIndexFull){
			var iDisplayStart = datatable_content.fnSettings()._iDisplayStart;
			$("td:eq(0)", nRow).html(iDisplayStart+iDisplayIndex+1);
		}
		
		function query(){
			datatable_content.fnDestroy();
			initTable();
		}
        $(function() {
		    $("#queryForm").validate(); 
		  	$("#_fromDate").datepicker({ format : 'yyyy-mm-dd' });
			initTable();
			formParam = $("#queryForm").serializeArray();
       });
        
        function exportExcel(){
      		$("#queryForm").attr("action","${ctx}/invHistory/exportExcel");
	        $("#queryForm").submit();
			$("#queryForm").attr("action","${ctx}/invHistory/v2_toQuery");
      }
    </script>
</head>

<body>
<section class="content">
		<div class="row">
			<div class="col-md-12">
			<div class="box box-solid box-primary">
			<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏 进出存报表</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
			<form class="form-search" id="queryForm" action="${ctx}/invHistory/v2_toQuery" method="post">
			<div class="form-group row">
			<div class="col-sm-3">
				<div class="input-textgroup col-sm-12">
					<span class="input-group-text">商家：</span>
					<select  name="_customerCode"  id="_customerCode" value="${param._customerCode}" class="form-control required" >
						<option value=""></option>
						<c:forEach items="${customerList}" var="customer">
							<option value="${customer.customerCode}"
							<c:if test="${param._customerCode eq customer.customerCode}">selected=selected</c:if>
							>${customer.customerName}</option>
						</c:forEach>
					</select>
				</div>
			</div>
			
			<div class="col-sm-3">
				<div class="input-textgroup col-sm-12">
					<span class="input-group-text">仓库：</span>
					<select  name="_warehouseCode"  id="_warehouseCode" class="form-control">
						<option value=""></option>
						<c:forEach items="${warehouseList}" var="w">
						   <option value="${w.groupCode}" 
						   <c:if test="${param._warehouseCode eq w.groupCode }">selected=selected</c:if>
						   >${w.groupName}</option>
					   </c:forEach>
					</select>
				</div>
			</div>
			
			 <div class="col-sm-3">
				<div class="input-group col-sm-12">
				<label class="input-group-text">商品编码:</label>
				<input type="text" id="_sku" name="_sku"  class="form-control" value="${param._sku}"/>
				</div>
				</div>
		</div>	
			
			  <div class="form-group row">
				<div class="col-sm-3">
				<div class="input-group col-sm-12">
				<label class="input-group-text">时间:</label> 
			 	<input type="text" name="_fromDate" id="_fromDate"  class="form-control required" value="${param._fromDate}" /> 
			 	</div>
			 	</div>
				
				<div class="col-sm-3">
				<div class="input-group col-sm-12">
			    	<button type="submit" class="btn btn-info">搜索</button>
			   		<a class="btn btn-primary"  href="#" onclick="exportExcel();return false;">导出库存报表</a>
			   	</div>
			    </div>
			    
				</div>
		    </form>
	   
</div>
</div>
</div>
</div>
	
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-primary">
				<div class="box-header"></div>
				<div class="box-body">
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>
			    <th>序号</th>
			    <th>商家</th>
			    <th>仓库</th>
			    <th>日期</th>
			    <th>商品编码</th>
			    <th>商品名称</th>
			    <th>期初库存</th>
			    <th>本期入</th>
			    <th>本期出</th>
			    <th>本期调整</th>
			    <th>期末库存</th>
			</tr></thead>
		<tbody>
		</tbody>
	</table>
	</div>
	</div>
	</div>
	</div>
</section>	
</body>
</html>
